package org.train.model.impl;

import java.util.Collections;
import java.util.List;

import org.train.model.Car;
import org.train.model.Locomotive;
import org.train.model.Train;

public class TrainImpl implements Train {
	protected List<Car> carList;
	private final double maxSpeed;
	private final double weight;

	public TrainImpl(List<Car> carList) {
		this.carList = carList;
		double maxSpeed = Double.MAX_VALUE;
		double weight = 0.0;
		for (Car car : carList) {
			if (Math.abs(car.getMaxSpeed()) < maxSpeed) {
				maxSpeed = Math.abs(car.getMaxSpeed());
			}
			weight += Math.abs(car.getWeight());
		}
		this.maxSpeed = maxSpeed;
		this.weight = weight;

	}

	@Override
	public final double getMaxSpeed() {
		return maxSpeed;
	}

	@Override
	public final int getCarNumber() {
		return carList.size();
	}

	@Override
	public final double getWeight() {
		return weight;
	}

	@Override
	public List<Locomotive> getLocomotiveList() {
		// TODO Auto-generated method stub
		throw new RuntimeException("Not yet supported");
	}

	@Override
	public List<Car> getCarList() {
		return Collections.unmodifiableList(carList);
	}

}
